package com.gexin.common.xapp;

import com.alibaba.fastjson.JSON;
import com.gexin.model.weixin.WeixinAppConfig;
import com.jfinal.kit.HttpKit;
import com.jfinal.wxaapp.WxaConfig;
import com.jfinal.wxaapp.api.WxaAccessTokenApi;

import java.util.HashMap;
import java.util.Map;

/**
 * 小程序配置工具
 * @author L.cm
 *
 */
public class ContentFilteringKit {
	private static String imgSecCheckUrl = "https://api.weixin.qq.com/wxa/img_sec_check?access_token=";
	private static String mediaCheckAsyncUrl = "https://api.weixin.qq.com/wxa/media_check_async?access_token=";
	private static String msgSecCheckUrl = "https://api.weixin.qq.com/wxa/msg_sec_check?access_token=";


	public static String imgSecCheck(String media){
		WxaConfigKit.setThreadLocalAppid("wxdb4a18fe5731ee4a");
		String access_token= WxaAccessTokenApi.getAccessTokenStr();
		String url=msgSecCheckUrl+access_token;
		Map<String,String> params=new HashMap<String, String>();
		params.put("media",media);
		String result = HttpKit.post(url, JSON.toJSONString(params));
		return result;
	}

	public static String mediaCheckAsync(Integer media_type,String media_url){
		WxaConfigKit.setThreadLocalAppid("wxdb4a18fe5731ee4a");
		String access_token= WxaAccessTokenApi.getAccessTokenStr();
		String url=msgSecCheckUrl+access_token;
		Map<String,Object> params=new HashMap<String, Object>();
		params.put("media_url",media_url);
		params.put("media_type",media_type);
		String result = HttpKit.post(url,JSON.toJSONString(params));
		return result;
	}

	public static String msgSecCheck(String content){
		WxaConfig wc= WeixinAppConfig.dao.findFirst("SELECT * from t_weixin_app_config where app_id='wxdb4a18fe5731ee4a' ").getWxaConfigs();
		com.jfinal.wxaapp.WxaConfigKit.setWxaConfig(wc);
		/*WxaConfigKit.setThreadLocalAppid("wxdb4a18fe5731ee4a");*/
		String access_token= WxaAccessTokenApi.getAccessTokenStr();
		String url=msgSecCheckUrl+access_token;
		Map<String,String> params=new HashMap<String, String>();
		params.put("content",content);
		String result = HttpKit.post(url, JSON.toJSONString(params));
		return result;
	}

}
